<?php

	class HomeController extends AppController
	{
		var $uses = array('Product');
		
		var $publicAction = array('index');
		
		function index()
		{
			$this->helpers[] = 'Number';
			$this->pageTitle = __('Comprar nunca fue tan fácil', true);
			
			$this->Product->Behaviors->attach('Containable');
			
			$last_products = $this->Product->find(
				'all',
				array(
					'conditions' => array(
						'Shop.disabled' => 0,
						'Shop.deleted' => 0,
						'Product.deleted' => 0,
						'Product.disabled' => 0
					),
					'fields' => array(
						'DISTINCT (Product.shop_id)',
						'Shop.alias',
						'Product.id',
						'Product.price',
						'CONCAT(\''. Configure::read('App.Url.media') . 'images/products/\',Shop.alias,\'/\', REPLACE(Product.preview,\'.\',\'_thumb.\')) AS preview',
						//
						'Currency.code',
						'Currency.symbol_left',
						'Currency.symbol_right',
						'Currency.decimal_places',
						'Currency.decimals',
						'Currency.thousands',
						//
						'ProductDescription.name',
						'ProductDescription.slug'
					),
					'contain' => array(
						'Shop',
						'Currency',
						'ProductDescription'
					),
					'limit' => 20,
					//'group' => 'Product.shop_id',
					'order' => 'Product.created DESC',
					'recursive' => 0
				)
			);
			
			$shops = $this->Product->Shop->find(
				'all',
				array(
					'conditions' => array(	
						'Shop.disabled' => 0,
						'Shop.deleted' => 0
					),
					'fields' => array(
						'Shop.name',
						'Shop.alias',
						'IF(Shop.logo != \'\''
						. ', CONCAT(\''. Configure::read('Minicatalogo.url') . 'media/shop/\',Shop.id,\'/\', Shop.logo)'
						. ', \''. Configure::read('Minicatalogo.url') . 'media/shop_prev.png\''
						. ') AS logo'
						,
						//'CONCAT(\''. Configure::read('Minicatalogo.url') . 'media/shop/\',Shop.slug,\'/\', REPLACE(Shop.logo,\'.\',\'_40x40.\')) AS logo'
					),
					'order' => 'RAND() DESC',
					'limit' => 30,
					'recursive' => -1
				)
			);
			
			$this->set(compact('last_products','shops'));
		}
	}

?>